<template>
    <div>
        <u><a>校区管理</a></u>
        <div>
            <a @click="show = !show">所有校区</a>
                    <div v-show="show">
                        <font color='blue'>校区列表:</font>
                        <table border="1" placeholder="0">
                            <tr>
                                <td>校区id</td>
                                <td>校区名</td>
                                <td>校区说明</td>
                                <td>操作</td>
                            </tr>
                             <tr v-for="i in school_list">
                                <td>{{i.id}}</td>
                                <td>{{i.name}}</td>
                                <td>{{i.desc}}</td>
                                <td><van-button color='red' @click="s_update(i.id)">编辑</van-button></td>
                            </tr>
                        </table>
                    </div>
            <a @click="a_school = !a_school">添加校区</a>
                    <div v-show="a_school">
                        <van-field type="text" label="校区名称" placeholder="" v-model="schoolfrom.name"/>
                        <van-field type="text" label="校区说明" placeholder="" v-model="schoolfrom.desc"/>
                        <van-button type="primary" @click="add_school">确认添加</van-button>
                    </div>

        </div>
        <u><a>班级管理</a></u>
        <div>
            <a @click="c_show = !c_show">所有班级</a>
                    <div v-show="c_show">
                        <font color='red'>班级列表</font>
                        <table border="1">
                            <tr>
                                <td>班级id</td>
                                <td>班级名</td>
                                <td>班级说明</td>
                                <td>所在校区</td>
                                <td>开班时间</td>
                                <td>结课时间</td>
                                <td>操作</td>
                            </tr>
                            <tr v-for="i in class_list">
                                <td>{{i.id}}</td>
                                <td>{{i.name}}</td>
                                <td>{{i.desc}}</td>
                                <td v-for="j in school_list" v-if='j.id == i.zid'>{{j.name}}</td>
                                <td>{{i.start_time}}</td>
                                <td>{{i.end_time}}</td>
                                <td><van-button color='red'>编辑</van-button></td>
                            </tr>
                        </table>
                    </div>
             <a @click="add_class = !add_class">添加班级</a>
                    <div v-show="add_class">
                        <van-field type="text" label="班级名" placeholder="" v-model="classfrom.name"/>
                        <van-field type="text" label="班级说明" placeholder="" v-model="classfrom.desc"/>
                        所在校区:<select name="" id="" v-model="classfrom.zid">
                            <option :value="i.id" v-for="i in school_list">{{i.name}}</option>
                        </select><br>
                        开班时间:<input type="date" v-model="classfrom.start_time"><br> 
                        结束时间:<input type="date" v-model="classfrom.end_time">
                        <van-button type="primary" @click="add_classs">添加班级信息</van-button>
                    </div>
        </div>
        <u><a>学员管理</a></u>
        <div>
            <a @click="w_show = !w_show">我的学员</a>
                    <div v-show="w_show">
                        <font color='red'>学员列表</font>
                        <table border="1">
                            <tr>
                                <td>id</td>
                                <td>姓名</td>
                                <td>性别</td>
                                <td>手机</td>
                                <td>专业</td>
                                <td>学历</td>
                                <td>班级</td>
                                <td>校区</td>
                                <td>操作</td>
                            </tr>
                            <tr v-for="i in stu_list">
                                <td>{{i.id}}</td>
                                <td>{{i.name}}</td>
                                <td v-if="i.sex == 1">男</td>
                                <td v-if="i.sex == 2">女</td>
                                <td>{{i.phone}}</td>
                                <td>{{i.brick}}</td>
                                <td>{{i.education}}</td>
                                <td v-for="j in class_list" v-if="j.id == i.cid">{{j.name}}</td>
                                <td v-for="j in school_list" v-if="j.id == i.zid">{{j.name}}</td>
                                <td><van-button color='red'>编辑</van-button></td>
                            </tr>
                        </table>
                    </div>
            
            <a @click="index_stu = !index_stu">搜索学员</a>
                    <div v-show='index_stu'>
                        <van-field type="text" label="搜索学员姓名" placeholder="" v-model="stu_name"/>
                        <van-button type="primary" @click='index_student'>查询信息</van-button>
                    </div>
            <a @click="add_stu = !add_stu">登记学员</a>
                    <div v-show="add_stu">
                        <van-field type="text" label="姓名" placeholder="" v-model="stufrom.name"/>
                        <input type="radio" :value="1" v-model="stufrom.sex">男
                        <input type="radio" :value="2" v-model="stufrom.sex">女
                        <van-field type="text" label="手机号" placeholder="" v-model="stufrom.phone"/>
                        <van-field type="text" label="专业" placeholder="" v-model="stufrom.brick"/>
                        <van-field type="text" label="学历" placeholder="" v-model="stufrom.education"/>
                        所在校区:<select name="" id="" v-model="stufrom.zid" @change="get_stuclass">
                            <option :value="i.id" v-for="i in school_list">{{i.name}}</option>
                        </select><br>
                        所在班级:<select name="" id="" v-model="stufrom.cid">
                                    <option :value="i.id" v-for="i in cla_list">{{i.name}}</option>
                                </select>
                        <van-button type="primary" @click="add_student">添加班级信息</van-button>
                    </div>
        </div>
        {{mohu}}
    </div>
</template>

<script>
export default {
   data () {
      return {
          //所有校区信息
          show:false,
          school_list:'',
          a_school:false,
          schoolfrom:{},
          school_one:'',
          //班级信息
          c_show:false,
          class_list:'',
          add_class:false,
          classfrom:{},
          //学员信息
          w_show:false,
          stu_list:'',
          add_stu:false,
          index_stu:false,
          stu_name:'',
          stufrom:{},
          cla_list:'',
          mohu:''
      };
   },

    methods: {
        //展示所有学校
            show_school:function(){
                    this.axios.get(this.localhost+'show_school/')
                    .then(res=>{
                        console.log(res);
                        this.school_list = res.data;
                    })
            },
        //添加新学校
            add_school:function(){
                    this.axios.post(this.localhost+'add_school/',this.qs.stringify(this.schoolfrom))
                    .then(res=>{
                        console.log(res);
                        if (res.data.code == 200){
                            this.$toast.success('学院添加成功');
                            this.schoolfrom = {};
                            this.show_school();
                        }else{
                            this.$toast.fail(res.data.meg);
                        }
                    })
            },
        //编辑获取单个信息
            s_update:function(id){
                    this.axios.get(this.localhost+'show_school/?id='+id)
                    .then(res=>{
                        console.log(res);
                        this.school_one = res.data;
                    })
            },
        //添加班级信息
            add_classs:function(){
                    this.axios.post(this.localhost+'add_class/',this.qs.stringify(this.classfrom))
                    .then(res=>{
                        console.log(res);
                        if (res.data.code == 200){
                            this.$toast.success('班级添加成功');
                            this.get_class();
                            this.classfrom = {};
                        }else{
                            this.$toast.fail(res.data.meg);
                        }
                    })
            },
        //展示班级信息
            get_class:function(){
                    this.axios.get(this.localhost+'get_class/')
                    .then(res=>{
                        console.log(res);
                        this.class_list = res.data
                    })
            },
        //添加学生信息
            add_student:function(){
                    this.axios.post(this.localhost+'add_student/',this.qs.stringify(this.stufrom))
                    .then(res=>{
                        console.log(res);
                        if (res.data.code == 200){
                            this.$toast.success('学生信息添加成功');
                            this.get_stu();
                        }else{
                            this.$toast.fail('学生信息添加失败');
                        }
                    })
            },
        //获取学生信息
            get_stu:function(){
                    this.axios.get(this.localhost+'get_stu/')
                    .then(res=>{
                        console.log(res);
                        this.stu_list = res.data;
                    })
            },
        //当学生选择学校时,自动获取班级信息
            get_stuclass:function(){
                this.axios.get(this.localhost+'get_stuclass/?zid='+this.stufrom['zid'])
                .then(res=>{
                    console.log(res);
                    this.cla_list = res.data;
                })
            },
        //模糊查询学生信息
            index_student:function(){
                this.axios.get(this.localhost+'get_stu/?name='+this.stu_name)
                .then(res=>{
                    console.log(res);
                    this.mohu = res.data;
                })
            }
       },

    computed: {

       },

    created () {

       },

    mounted() {
        //自动获取学校信息
            this.show_school();
        //自动获取班级信息
            this.get_class();
        //自动获取学生信息
            this.get_stu();
            
       },

    components: {

       }
}
</script>
<style lang='css' scoped>

</style>